<script lenguage='javascript'>

var fechaStr;

$(function() {
        $(".datepicker").datepicker({ dateFormat: "yy-mm-dd" });
       
});

function sumarDia(fecha){

	fecha=fecha.replace("-", "/").replace("-", "/");  
	var temp = new Date(fecha);
	var result = '';

	var dia = temp.getDate();
	var mes = temp.getMonth();
	var anio = temp.getFullYear();
	
	switch(mes){//sumar dia
		case 0: case 2: case 4: case 6: case 7: case 9: case 11:
			dia = (dia + parseInt(1))%32;						
			break;
		case 1: //febrero
			if((anio%4) == 0)
				dia = (dia + parseInt(1))%30;
			else
				dia = (dia  + parseInt(1))%29;
			break;
		case 3: case 5: case 8: case 10:
			dia = (dia + parseInt(1))%31;
			break;
	}
	
	if(dia == 0){ //sumar mes
		dia = 1;
		mes = mes +1;
		if(mes == 12){//sumar año
			mes = 0;
			anio = anio +1; 
		}
	}
	
	result = result+anio+'-';
	if(mes <9)
		result = result+'0'+(mes+1)+'-';
	else
		result = result+(mes+1)+'-';

	if(dia < 10)
		return result+'0'+dia;
	else
		return result+dia;
	
	
}

function updateF1(val){

	document.getElementById("fecha1").innerHTML = val+' a las 00:00';
}

function updateF2(val){
	document.getElementById("fecha2").innerHTML = val+' a las 23:59';		
	document.getElementById("fecha3").innerHTML = sumarDia(val)+' a las 00:00';
}

function updateF3(val){
	document.getElementById("fecha4").innerHTML = val+' a las 23:59';
	document.getElementById("fecha5").innerHTML = sumarDia(val) +' a las 00:00';
}

function updateF4(val){
	document.getElementById("fecha6").innerHTML = val+' a las 23:59';
}
</script>


<h1>Preinscripción Academica</h1>

<h3><?php echo $this->PreinscriptionProcess->mensaje($proceso); ?></h3>

<table>
	<tr align='center'>
		<th width='33%'>Carga y modificación de cursos</th>
		<th width='33%'>Preinscripción Alumnos</th>
		<th width='34%'>Preinscripción y validación de resultados</th>
	</tr>
</table>
<?php echo $this->Form->create('PreinscriptionProcess', array('action'=> 'edit_period')); ?>
<table>
	<tr align='center'>
		<th width='25%'>Inicio</th>
		<th width='25%'>Fin / Inicio </th>
		<th width='25%'>Fin / Inicio</th>
		<th width='25%'>Fin</th>
	</tr>
	<tr align='center'>
		<td width='25%'><?php echo $this->Form->input('section_load_begin_date', array(
			'label' => '',
			'class'=>'datepicker',
			'type'=>'text',
			'readonly' => 'readonly',
			'onchange' => 'updateF1(this.value);'
        )); ?></td>
		<td width='25%'><?php echo $this->Form->input('obtaining_demand_begin', array(
			'label' => '',
			'class'=>'datepicker',
			'type'=>'text',
			'readonly' => 'readonly',
			'onchange' => 'updateF2(this.value);'
		)); ?></td>
		<td width='25%'><?php echo $this->Form->input('presentation_validation_of_results_begin', array(
			'label' => '',
			'class'=>'datepicker',
			'type'=>'text',
			'readonly' => 'readonly',
			'onchange' => 'updateF3(this.value);'
		)); ?></td>
		<td width='25%'><?php echo $this->Form->input('end_of_the_process', array(
			'label' => '',
			'class'=>'datepicker',
			'type'=>'text',
			'readonly' => 'readonly',
			'onchange' => 'updateF4(this.value);'
		)); ?></td>
	</tr>
</table>



</br>
<h4> Exactamente esto significa que: </h4>
</br>

<table>
	<tr>
		<th width='34%'></th>
		<th width='33%'>Inicia</th>
		<th width='33%'>Finaliza</th>
	</tr>
	<tr>
		<td width='34%'>Carga y modificación de cursos</td>
		<td id='fecha1' width='33%'><?php echo $this->PreinscriptionProcess->sumarDias($proceso[0]['PreinscriptionProcess']['section_load_begin_date'], 0, ' a las 00:00'); ?></td>
		<td id='fecha2' width='33%'><?php echo $this->PreinscriptionProcess->sumarDias($proceso[0]['PreinscriptionProcess']['obtaining_demand_begin'], 0, ' a las 23:59'); ?></td>
	</tr>
	<tr>
		<td width='34%'>Preinscrioción Alumnos</td>
		<td id='fecha3' width='33%'><?php echo $this->PreinscriptionProcess->sumarDias($proceso[0]['PreinscriptionProcess']['obtaining_demand_begin'], 1,' a las 00:00'); ?></td>
		<td id='fecha4' width='33%'><?php echo $this->PreinscriptionProcess->sumarDias($proceso[0]['PreinscriptionProcess']['presentation_validation_of_results_begin'], 0 ,' a las 23:59'); ?></td>
	</tr>
	<tr>
		<td width='34%'>Presentación y validación de resultados</td>
		<td id='fecha5' width='33%'><?php echo $this->PreinscriptionProcess->sumarDias($proceso[0]['PreinscriptionProcess']['presentation_validation_of_results_begin'], 1, ' a las 00:00'); ?></td>
		<td id='fecha6' width='33%'><?php echo $this->PreinscriptionProcess->sumarDias($proceso[0]['PreinscriptionProcess']['end_of_the_process'], 0 , ' a las 23:59'); ?></td>
	</tr>
</table>

</br></br>

<table width='50'>
	<tr>
		<th width='30%'>Activo:</th>
		<th width='70%'><?php echo $this->PreinscriptionProcess->procesoActivo($proceso);?></th>
	</tr>
</table>

<?php echo $this->Html->link('Volver', array('action' => 'index')); ?> &nbsp;
<?php echo $this->Html->link('Editar Cursos', array('controller'=> 'Sections' ,'action'=> 'index', $proceso[0]['PreinscriptionProcess']['id'])); ?> &nbsp;
<?php echo $this->Form->end('Guardar Cambios'); ?>

<?php //} ?>



 
